//
//  TipsView.m
//  Malena
//
//  Created by Dawn on 12-11-4.
//  Copyright (c) 2012年 Dawn. All rights reserved.
//

#import "TipsView.h"
#define TITLEWIDTH 60
@implementation TipsView
@dynamic tips;
@dynamic title;
@synthesize screenSize;
@synthesize down = _down;

- (void) dealloc{
    self.tips = nil;
    self.title = nil;
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        // 分类
        categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(6, 4, frame.size.width - 12, 14)];
        categoryLabel.font = [UIFont systemFontOfSize:12.0f];
        categoryLabel.backgroundColor = [UIColor clearColor];
        categoryLabel.textColor = MAINTEXTCOLOR;
        [self addSubview:categoryLabel];
        
        // tips
        desLabel = [[UILabel alloc] initWithFrame:CGRectMake(6, 20, frame.size.width - 12, 0)];
        desLabel.numberOfLines = 0;
        desLabel.font = [UIFont systemFontOfSize:12.0f];
        desLabel.lineBreakMode = UILineBreakModeWordWrap;
        desLabel.backgroundColor = [UIColor clearColor];
        desLabel.textColor = MAINTEXTCOLOR;
        [self addSubview:desLabel];
        
        self.backgroundColor = MAINBGCOLOR;
        
        self.down = NO;
    }
    return self;
}

- (void) setTips:(NSString *)tips{
   // desLabel.text = @"";
    
    [UIView beginAnimations:@"TipsAction" context:nil];
    [UIView setAnimationDuration:0.3];
    
    CGSize size = CGSizeMake(screenSize.width - 12, 10000);
    UIFont *font = [UIFont systemFontOfSize:12.0f];
    CGSize desSize = [tips sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
    desLabel.frame = CGRectMake(desLabel.frame.origin.x, desLabel.frame.origin.y, desSize.width, desSize.height);
    
    if (_down) {
        self.frame = CGRectMake(0, screenSize.height, screenSize.width, desLabel.frame.size.height + 30);
    }else{
        self.frame = CGRectMake(0, screenSize.height - desLabel.frame.size.height - 10 - 20, screenSize.width, desLabel.frame.size.height + 10 + 20);
    }
    
   
    desLabel.text = tips;
   
    [UIView commitAnimations];
}

- (NSString *)tips{
    return desLabel.text;
}

- (void) setTitle:(NSString *)title{
    categoryLabel.text = title;
}

- (NSString *) title{
    return categoryLabel.text;
}

- (void) layoutSubviews{
    categoryLabel.frame = CGRectMake(6, 4, self.frame.size.width, 14);
    
    CGSize size = CGSizeMake(screenSize.width - 12, 10000);
    UIFont *font = [UIFont systemFontOfSize:12.0f];
    CGSize desSize = [desLabel.text sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
    desLabel.frame = CGRectMake(desLabel.frame.origin.x,desLabel.frame.origin.y, desSize.width,desSize.height);
    if (_down) {
        self.frame = CGRectMake(0, screenSize.height, screenSize.width, desLabel.frame.size.height + 30);
    }else{
        self.frame = CGRectMake(0, screenSize.height - desLabel.frame.size.height - 10 - 20, screenSize.width, desLabel.frame.size.height + 10 + 20);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
